import axios from "@/utils/request"
import { baseUrl } from '@/config/index';


export const userlogin = function (username:string,password:string) {
    console.log(username,password);
    const url = baseUrl + '/login';
    return axios.post(url, {
        username,
        password
    }).then((res:any)=>{
        if(res.data.code==1){
            localStorage.setItem("key",res.data.token)
            // this.$router.push({
            //   path:"/home"
            // })
            window.location.href="/"
        }else{
            alert("密码错误,重输")
          }
    })
}
export const userregister = function (username:string,password:string) {
    console.log(username,password);
    const url = baseUrl + '/registry';
    return axios.post(url, {
        username,
        password
    }).then((res:any)=>{
        if(res.data.code==-1){
            alert("注册失败,账号已注册")
        }else{
            alert("注册成功")
            window.location.href="/login"
          }
    })
}
